package com.xhs.zdl.demo.addressChoose;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xhs.zdl.demo.R;

import java.util.List;

/**
 * Created by zdl on 2017/11/8.
 * email zdl328465042@163.com
 */

public class AreaAdapter extends BaseAdapter {
    private List<String> data;
    private int lastPosition;
    private LayoutInflater inflater;

    public AreaAdapter(Context context, List<String> data) {
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (null == view){
            view =  inflater.inflate(R.layout.area_list_item, viewGroup,false);
            holder = new ViewHolder();
            holder.textView = (TextView) view.findViewById(R.id.area_tv);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }

        holder.textView.setText(data.get(position));

//        if (lastPosition<position && lastPosition!=0){
//            ObjectAnimator.ofFloat(view,"translationY",view.getHeight()*2,0).setDuration(500).start();
//
//        }
        lastPosition = position;
        return view;
    }

    class ViewHolder{
        TextView textView;
    }
}
